package com.yang.service.wximpl;

import com.yang.bean.MarketOrderExample;
import com.yang.bean.zdd.vo.IndexVoInWxVo;
import com.yang.bean.zdd.vo.UserOrderVo;
import com.yang.mapper.MarketOrderMapper;
import com.yang.service.wx.WXUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName WXUserServiceImpl
 * @Description TODO
 * @Author zhangdongdong
 * @Date 2022/9/10 11:33
 * @Version 1.0
 */
@Service
public class WXUserServiceImpl implements WXUserService {
    @Autowired
    MarketOrderMapper orderMapper;

    /**
     * @description: 用户登陆后显示用户相关信息
     * @param: id
     * @return: com.yang.bean.zdd.vo.IndexVoInWxVo
     * @author zhangdongdong
     * @date: 2022/9/11 9:55
     */
    @Override
    public IndexVoInWxVo index(Integer id) {
        IndexVoInWxVo data = new IndexVoInWxVo();

        //查询uncomment
        MarketOrderExample orderExample = new MarketOrderExample();
        orderExample.createCriteria().andUserIdEqualTo(id).andCommentsEqualTo((short) 1);
        long uncomment = orderMapper.countByExample(orderExample);

        //查询unpaid
        MarketOrderExample orderExample1 = new MarketOrderExample();
        orderExample1.createCriteria().andUserIdEqualTo(id).andOrderStatusEqualTo((short) 101);
        long unpaid = orderMapper.countByExample(orderExample1);

        //查询unrecv
        MarketOrderExample orderExample2 = new MarketOrderExample();
        orderExample2.createCriteria().andUserIdEqualTo(id).andOrderStatusEqualTo((short) 301);
        long unrecv = orderMapper.countByExample(orderExample2);

        //查询unship
        MarketOrderExample orderExample3 = new MarketOrderExample();
        orderExample3.createCriteria().andUserIdEqualTo(id).andOrderStatusEqualTo((short) 201);
        long unship = orderMapper.countByExample(orderExample3);

        UserOrderVo userOrderVo = new UserOrderVo();
        userOrderVo.setUncomment((int) uncomment);
        userOrderVo.setUnrecv(((int) unrecv));
        userOrderVo.setUnpaid((int) unpaid);
        userOrderVo.setUnship((int) unship);

        data.setOrder(userOrderVo);

        return data;
    }
}
